package com.tender.utils;

import io.jsonwebtoken.Claims;

public class JwtUtils {

    /**
     * 为了测试生成了一个永久有效的 jwtToken, 具体如下：
     * eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwNzYyZjhlYS1jNDE4LTQ2ZGUtOGZkNi1kMjVkYTk1Mzk2NmYiLCJ1c2VyX25hbWUiOiJsdWN5IiwiaWF0IjoxNzI0OTAxMTUxLCJhZ2UiOjEwLCJqdGkiOiI4ODg4ODg4OCJ9.sGv6rglWbNsaAuZvcqsD7yy_OANVgYe7ZNGOPQ_j4Uk
     *
     * {"sub":"0762f8ea-c418-46de-8fd6-d25da953966f","user_name":"lucy","iat":1724901151,"age":10,"jti":"88888888"}
     */
    public static LoginUser  getClientUserInfo(String jwtToken) {
        // 验证 jwtToken 有效性
        JwtTokenManager.verifyToken(jwtToken);

        Claims claims = JwtTokenManager.decodeToken(jwtToken);

        // TODO 目前写死
        LoginUser  userInfo = new LoginUser ();
        userInfo.setUsername(claims.get("user_name", String.class));
        userInfo.setUserId(claims.get("sub", Long.class));

        return userInfo;
    }

}
